<?php

declare(strict_types=1);

namespace App\Listener;

use App\Services\YunXinCloud\WyyChatRoomMessageClient;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;

#[Listener]
class KickMemberListener implements ListenerInterface
{
    public function __construct(protected ContainerInterface $container)
    {
    }

    public function listen(): array
    {
        return [
            \App\Event\KickMemberNotify::class,
        ];
    }

    public function process(object $event): void
    {
        $userInfo = $event->userInfo;
        $roomId = $event->roomId;
        $uid = $event->uid;
        logInfo('KickMemberListener', [$roomId, $userInfo]);
        $message = json_encode(['event' => 'kick_user', 'msg' => ['userInfo' => $userInfo]]);
        $this->container->get(WyyChatRoomMessageClient::class)->sendCustomRoomMsg($roomId, $message, $uid);
    }
}
